// pages/salecenter/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    agentList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.core('get', 'getCashMoneyAgent', '', (res) => {
      this.setData({
        agentList: res.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  // 经纪人菜单
  tocommission() {
    wx.navigateTo({
      url: '/pages/agent/commission/index',
    })
  },
  tocustomer() {
    wx.navigateTo({
      url: '/pages/agent/index',
    })
  },
  tomycust() {
    wx.navigateTo({
      url: '/pages/agent/mycust/index',
    })
  },
  toMymoney() {
    wx.navigateTo({
      url: '/pages/agent/mymoney/index',
    })
  },
  // 置业顾问留言板
  tomessage() {
    wx.navigateTo({
      url: '/pages/adviser/reply/reply',
    })
  },
  // 追加楼盘
  toaddbuilding() {
    wx.navigateTo({
      url: '/pages/readviser/addbuilding/addbuilding',
    })
  },
  // 我的楼盘
  toMybuilding() {
    let adviser_id = this.data.isAdviser
    wx.navigateTo({
      url: `/pages/adviser/mybuilding/mybuilding?adviser_id=${adviser_id}`,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let open_id = wx.getStorageSync('user_new')
    if (open_id == '') {
      return false
    }
    app.core('get', 'getUserInfo?open_id=' + open_id, '', (res) => {
      console.log(res)
      this.setData({
        isAdviser: res.data.adviser_id
      })
      // console.log(this.data.isAdviser)
    })
    app.core('get', 'findAgentByOpenid?open_id=' + open_id, '', (res) => {
      console.log(res)
      let resultCode = res.resultCode
      if (resultCode === 500) {
        this.setData({
          isAgent: 0,
        })
        return true
      }
      if (resultCode === 200) {
        let status = res.data.status
        this.setData({
          isAgent: status,
        })
      }
    }) 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})